package view;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import Dub.DubMaterial;
import controler.SistemaIndumentaria;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModificarMaterial extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;

	private static ModificarMaterial instModificarMaterial;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
	private JButton jBBuscar;
	private JLabel jLalerta;
	private JButton jBCancelar;
	private JButton jBAceptar;
	private JTextField jTextNombre;
	private JTextField jTextPuntoPedido;
	private JTextField jTextcodigo;
	private JTextField jTextCosto;
	private JTextField jTextStock;
	private JTextField jTextIdProveedor;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		ModificarMaterial inst = new ModificarMaterial();
		inst.setVisible(true);
	}
	
	private ModificarMaterial() {
		super();
		initGUI();
	}
	
	public static ModificarMaterial getInstance(boolean init)
	{
		if (instModificarMaterial==null)
		{
			instModificarMaterial= new ModificarMaterial();
			
		}
		if (init)
		{
			instModificarMaterial.inicializarPantalla();
		}
		return instModificarMaterial;
		
	}
	
	
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setTitle("Modificar Material");
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("CODIGO");
				jLabel1.setBounds(49, 21, 63, 21);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("NOMBRE");
				jLabel2.setBounds(49, 52, 63, 28);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("PTO. PEDIDO");
				jLabel3.setBounds(49, 83, 63, 28);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("COSTO");
				jLabel4.setBounds(49, 114, 63, 28);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("STOCK");
				jLabel5.setBounds(49, 145, 63, 28);
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("ID PROVEEDOR");
				jLabel6.setBounds(49, 176, 63, 28);
			}
			{
				jTextcodigo = new JTextField();
				getContentPane().add(jTextcodigo);
				jTextcodigo.setBounds(112, 21, 70, 21);
			}
			{
				jTextNombre = new JTextField();
				getContentPane().add(jTextNombre);
				jTextNombre.setBounds(112, 52, 224, 21);
			}
			{
				jTextPuntoPedido = new JTextField();
				getContentPane().add(jTextPuntoPedido);
				jTextPuntoPedido.setBounds(112, 83, 224, 21);
			}
						
			{
				jTextCosto = new JTextField();
				getContentPane().add(jTextCosto);
				jTextCosto.setBounds(112, 114, 224, 21);
			}
			{
				jTextStock = new JTextField();
				getContentPane().add(jTextStock);
				jTextStock.setBounds(112, 145, 224, 21);
			}
			{
				jTextIdProveedor = new JTextField();
				getContentPane().add(jTextIdProveedor);
				jTextIdProveedor.setBounds(112, 176, 224, 21);
			}
			{
				jBAceptar = new JButton();
				getContentPane().add(jBAceptar);
				jBAceptar.setText("ACEPTAR");
				jBAceptar.setBounds(49, 203, 110, 28);
				jBAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBAceptar.actionPerformed, event="
								+ evt);
						SistemaIndumentaria.getInstancia().modificarMaterial(Integer.parseInt(jTextcodigo.getText()),jTextNombre.getText(), Integer.parseInt(jTextPuntoPedido.getText()), Float.parseFloat(jTextCosto.getText()),Integer.parseInt(jTextStock.getText()),Integer.parseInt(jTextIdProveedor.getText()));
					}
				});
			}
			{
				jBCancelar = new JButton();
				getContentPane().add(jBCancelar);
				jBCancelar.setText("CANCELAR");
				jBCancelar.setBounds(224, 203, 110, 28);
				jBCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBCancelar.actionPerformed, event="
							+ evt);
						ModificarMaterial.getInstance(true).setVisible(false);
					}
				});
			}
			{
				jBBuscar = new JButton();
				getContentPane().add(jBBuscar);
				jBBuscar.setText("BUSCAR");
				jBBuscar.setBounds(210, 21, 119, 21);
				jBBuscar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jBBuscar.actionPerformed, event="+evt);
						DubMaterial dubm = null; 
						dubm = SistemaIndumentaria.getInstancia().buscarDubMaterial(Integer.parseInt(jTextcodigo.getText()));
						if (dubm == null)
						   {
							jLalerta.setForeground(Color.RED);
							jLalerta.setText("EL Material no existe");
						   }
						else
							{
							  jTextNombre.setText(dubm.getNombre());
							  String s=String.valueOf(dubm.getPuntoPedido());
							  jTextPuntoPedido.setText(s);
							  String t=String.valueOf(dubm.getCosto());
							  jTextCosto.setText(t);
							  String r=String.valueOf(dubm.getStock());
							  jTextStock.setText(r);
							  String u=String.valueOf(dubm.getIdProveedor());
							  jTextIdProveedor.setText(u);
							  						}				
					}
				});
			}
			{
				jLalerta = new JLabel();
				getContentPane().add(jLalerta);
				jLalerta.setBounds(49, 124, 287, 19);
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void inicializarPantalla()
	{
	
		}
	
	
	
}
